using System;
using System.Collections.Generic;

namespace NFreeMarker.Template
{
    /**
     * Singleton object representing nothing, used by ?if_exists built-in.
     * It is meant to be interpreted in the most sensible way possible in various contexts.
     * This can be returned to avoid exceptions.
     *
     * @author <a href="mailto:jon@revusky.com">Jonathan Revusky</a>
     */
    internal sealed class GeneralPurposeNothing
        : ITemplateBooleanModel, ITemplateScalarModel, ITemplateSequenceModel,
          ITemplateHashModelEx, ITemplateMethodModelEx
    {
        private static readonly ITemplateModel Instance = new GeneralPurposeNothing();
        //private static readonly ITemplateCollectionModel EMPTY_COLLECTION = new SimpleCollection(new ArrayList(0));

        private GeneralPurposeNothing()
        {
        }

        internal static ITemplateModel GetInstance()
        {
            return Instance;
        }

        public string GetAsString()
        {
            return "";
        }

        public bool GetAsBoolean()
        {
            return false;
        }

        public bool IsEmpty()
        {
            return true;
        }

        public int Size()
        {
            return 0;
        }

        public ITemplateModel Get(int i)
        {
            throw new TemplateModelException("Empty list");
        }

        public ITemplateModel Get(string key)
        {
            return null;
        }

        public object Exec(IList<string> args)
        {
            return null;
        }

        public object Exec(IList<ITemplateModel> args)
        {
            return null;
        }

        public ITemplateCollectionModel Keys()
        {
            //return EMPTY_COLLECTION;
            throw new NotImplementedException();
        }

        public ITemplateCollectionModel Values()
        {
            //return EMPTY_COLLECTION;
            throw new NotImplementedException();
        }
    }
}